/**
 * Created by thl on 2019/3/15.
 */
sType = getUrlParam("type"); //sType  1暂定裸钻，2 统包 3成品
//时间的
var calendarDateFormat = myApp.calendar({
    input: '#arrival_time',
    monthNames: ['01'+_(''+_('月')), '02'+_('月'), '03'+_('月'), '04'+_('月'), '05'+_('月'), '06'+_('月'), '07'+_('月'), '08'+_('月') , '09'+_('月') , '10'+_('月'), '11'+_('月'), '12'+_('月')],
    dayNamesShort: [_('日'), _('一'), _('二'), _('三'), _('四'), _('五'), _('六')],
    closeOnSelect:true,
});
var calendarDateFormat = myApp.calendar({
    input: '#receiptarrivalTime',
    monthNames: ['01'+_(''+_('月')), '02'+_('月'), '03'+_('月'), '04'+_('月'), '05'+_('月'), '06'+_('月'), '07'+_('月'), '08'+_('月') , '09'+_('月') , '10'+_('月'), '11'+_('月'), '12'+_('月')],
    dayNamesShort: [_('日'), _('一'), _('二'), _('三'), _('四'), _('五'), _('六')],
    closeOnSelect:true,
});
var recommendNum;
(function () {
    var product = {
        init: function () {
            var args = GetUrlParms();
            if(args["team"]!=undefined){
                TEAM = args["team"];
            }
            this.bindEvents();
            getRecommend();

        },
        bindEvents: function () {
            var self = this;

            //图片勾选
            $("#inlays,#inlaysettings").on("click",".check_list_box",function(){
                $(this).find("span").toggleClass("selected");
                if(sType==3){
                    var checkLength=$("#inlays .check_list_box span.selected").length;
                }else if(sType==7){
                    var checkLength=$("#inlaysettings .check_list_box span.selected").length;
                }
                if(checkLength>0){
                    $(".search_btn_b").css("background-color", primary_color);
                    $(".search_btn_b").attr("disabled", false);
                }else{
                   self.clearBtn();
                }

            });

            //批量修改所在地start
            $("#edit_place_btn").on("click",function(){
                myApp.popup("#ModPlace_box");
                //所在地
                if($("#place_box").html()==""){
                    var html_Place = '<option value="">' + _("所在地") + '</option>';
                    for(var i = 0; i < inlay[1].Country.length; i++) {
                        html_Place += '<option value="' + inlay[1].Country[i][0] + '">' + _(inlay[1].Country[i][1]) + '</option>';
                    }
                    $("#place_box").html(html_Place);
                }
            });
            $("#place_btn").on("click",function(){
                var val=$("#place_box").val();
                if(val==""){
                    myApp.alert(_("请选择"));
                }else{
                    self.batchUpdateDia(1,"#ModPlace_box");
                }
            });
            //批量修改所在地end

            //批量修改状态start
            $("#edit_status_btn").on("click",function(){
                myApp.popup("#ModStatus_box");
                var json_type;
                if(sType == 3){
                    json_type= inlay;
                    var checkLength=$("#inlays .check_list_box span.selected")
                }else if(sType == 7){
                    json_type = inlaysetting;
                    var checkLength=$("#inlaysettings .check_list_box span.selected")
                }
                //状态
                if($("#_batchstatus").html()==""){
                    var $Status = '<option value="">' + _("状态") + '</option>';
                        for(var i = 0; i < json_type[1].Status.length; i++) {
                            $Status += '<option value="' + json_type[1].Status[i][0] + '">' + _(json_type[1].Status[i][1]) + '</option>';
                        }
                    $("#_batchstatus").html($Status);
                }

                if(checkLength.length==1){
                    var _val=$("#inlays .check_list_box span.selected").eq(0).attr("data-comments"); //现货备注
                    var _val_status=$("#inlays .check_list_box span.selected").eq(0).attr("data-status"); //现货状态
                    $("#ModStatus_Comments").val(_val);
                    $("#_batchstatus").val(_val_status);
                }
            });
            $("#status_btn").on("click",function(){
                if($("#_batchstatus").val()==""){
                    myApp.alert(_("请选择"));
                }else{
                    self.batchUpdateDia(2,"#ModStatus_box");
                }
            });
            //批量修改状态end

            //改变调价选项 start
            $("#modInputPrice").on("change","input",function(){
                var val = $(this).attr("data-val");
                $(".modPrice:eq("+(val-1)+")").show().siblings(".modPrice").hide();
            });
            //批量调价成品
            $("#bulk_pricing_btn").on("click",function(){
                $("#_modPrice input.o_modPrice").val("");
                $("#title_tab span.active").css("background",$.cookie("ThemesColor"));
                myApp.popup("#batchDia_box");
            });
            //切换调价
            $("#title_tab").on('click','span',function(){
                $(this).addClass("active").siblings().removeClass("active");
                $(this).css("background",$.cookie("ThemesColor")).siblings("span").css("background","#ccc");
                if($("#title_tab span.active").attr("data-type")==2){
                    $("#factor").hide();
                    $("#price").show();
                }else{
                    $("#factor").show();
                    $("#price").hide();
                }
            });
            $('#batchDia').on('click',function(){
                self.ModifyPrice();
            });
            //确定调价 end

            //批量调价空托
            $("#bulk_inlaysettings_pricing_btn").on('click',function(){

                myApp.popup("#batch_price_box");
                var inventorylistCb = $("#inlaysettings .check_list_box span.selected");
                if(inventorylistCb.length==1){
                    var valWastage=inventorylistCb.attr("data-wastage");
                    var valLaborFee=inventorylistCb.attr("data-laborFee");
                    var valSideLaborFee=inventorylistCb.attr("data-sideLaborFee");
                    var valSidePrice=inventorylistCb.attr("data-sidePrice");
                    var valInsurance=inventorylistCb.attr("data-insurance");

                    $("#mod_Wastage").val(valWastage);
                    $("#mod_LaborFee").val(valLaborFee);
                    $("#mod_SideLaborFee").val(valSideLaborFee);
                    $("#mod_SidePrice").val(valSidePrice);
                    $("#mod_Insurance").val(valInsurance);
                }else{
                    $("#mod_LaborFee").val("");
                    $("#mod_SideLaborFee").val("");
                    $("#mod_SidePrice").val("");
                    $("#mod_Wastage").val("");
                    $("#mod_Insurance").val("");
                }
            });
            $("#ModPrice_btn").on('click',function(){
                self.ModifyPriceInlays();
            });

            //到货start
            $("#edit_arrival_btn").on("click",function(){
                myApp.popup("#arrival_box");
            });
            $("#arrival_btn").on("click",function(){
                if($("#arrival_time").val()==""){
                    myApp.alert(_("不能为空"));
                }else{
                    self.batchUpdateDia(3,"#arrival_box");
                }
            });
            //到货end

            //付款start
            $("#edit_payment_btn").on("click",function(){
                var ispay=[];
                var _usd=0;
                var _rmb=0;
                if(sType == 3){
                    var inventorylistCb = $("#inlays .check_list_box span.selected");//checked的
                }else if(sType == 7){
                    var inventorylistCb = $("#inlaysettings .check_list_box span.selected");//checked的
                }
                for (var i = 0; i < inventorylistCb.length; i++) {
                    if(inventorylistCb.eq(i).attr("data-receiptstatus")=="0"){//1为已付
                        ispay.push("0");
                        _usd+=Number(inventorylistCb.eq(i).attr("data-usd"));
                        _rmb+=Number(inventorylistCb.eq(i).attr("data-rmb"));
                    }
                }
                if(ispay.length==inventorylistCb.length){//未付的个数和选中的个数 一样则全部为未付的
                    $("#_receipt_usd").text(formatUSDPrice(_usd));
                    $("#_receipt_rmb").text(formatRMBPrice(_rmb));
                    self.ReceiptOrders_Js();
                }else{
                    myApp.alert(_("请选择未付的产品！"));
                }

            });

            //付款end

            //删除
            $("#del_choose_btn").on("click",function(){
                myApp.confirm(_("删除后无法恢复，确定要删除吗？"),function(){
                    self.delDia();
                });
            });

            //上下架start
            $("#shelves_btn").on('click',function(){
                myApp.popup("#shelves_box");
            })
            $("#form_shelves_choose span").on("click",function(){
                $(this).addClass("active").siblings().removeClass("active");
            });
            $("#shelves_form_btn").on("click",function(){
                self.productOnShelves(1);
            });
            //上下架end

            //买价start
            $("#edit_purchase_btn").on('click',function(){
                myApp.popup("#ModPurchasePrice_box");
                $('#origin_radio_purchaseRMB').prop('checked',true);
                $("#purchaseRMB_inp").val('');
                PurchaseRMBChange();
            })
            //买价end

            //款号
            $("#batch_styleNo").on("click",function(){
                myApp.popup("#batch_styleNo_box");
                if(sType == 3){
                    var inventorylistCb = $("#inlays .check_list_box span.selected");
                }else if(sType == 7){
                    var inventorylistCb = $("#inlaysettings .check_list_box span.selected");
                }
                if(inventorylistCb.length==1){
                    var valSeries=inventorylistCb.attr("data-styleNo");
                    $("#_batchStyleNo").val(valSeries);
                }else{
                    $("#_batchStyleNo").val('');
                }
            })

            //空托批量修改风格
            $("#batch_style").on("click",function(){
                myApp.popup("#batch_style_box");
                //风格
                var html_style=""
                html_style = '<option value="">' + _("风格") + '</option>';
                for(var i = 0; i < inlaysetting[1].Style.length; i++) {
                    html_style += '<option value="' + inlaysetting[1].Style[i][0] + '">' + _(inlaysetting[1].Style[i][1]) + '</option>';
                }
                $("#_batchStyle").html(html_style);
                if(sType == 3){
                    var inventorylistCb = $("#inlays .check_list_box span.selected");//checked的
                }else if(sType == 7){
                    var inventorylistCb = $("#inlaysettings .check_list_box span.selected");//checked的
                }
                if(inventorylistCb.length==1){
                    var valStyle=inventorylistCb.attr("data-style");
                    $("#_batchStyle").val(valStyle);
                }else{
                    $("#_batchStyle").html(html_style);
                }
            })
            $("#ModStyle_btn").on("click",function(){
                var val=$("#_batchStyle").val();
                if(val==""){
                    myApp.alert(_("请选择"));
                }else{
                    self.batchUpdateDia(5,"#batch_style_box");
                }
            });

            //系列
            $("#batch_series").on('click',function(){
                myApp.popup("#batch_series_box");
                if(sType == 3){
                    var inventorylistCb = $("#inlays .check_list_box span.selected");
                }else if(sType == 7){
                    var inventorylistCb = $("#inlaysettings .check_list_box span.selected");
                }
                if(inventorylistCb.length==1){
                    var valSeries=inventorylistCb.attr("data-series");
                    $("#_batchSeries").val(valSeries);
                }else{
                    $("#_batchSeries").val('');
                }
            });
            //修改成品证书
            $("#certtype_btn").on("click",function(){
                myApp.popup("#batch_certtype_box")
                var inventorylistCb = $("#inlays .check_list_box span.selected");
                if(inventorylistCb.length==1){
                    var valTechnics=inventorylistCb.attr("data-certtype");
                    $("#_batchcerttype").val(valTechnics);
                }else{
                    $("#_batchcerttype").val('');
                }
            });

            //主石工艺空托
            $("#batch_technics").on('click',function(){
                myApp.popup("#batch_technics_box");
                var html_Technics=""
                html_Technics = '<option value="">' + _("主石工艺") + '</option>';
                for(var i = 0; i < inlaysetting[1].Technics.length; i++) {
                    html_Technics += '<option value="' + inlaysetting[1].Technics[i][0] + '">' + _(inlaysetting[1].Technics[i][1]) + '</option>';
                }
                $("#_batchTechnics").html(html_Technics);
                var inventorylistCb = $("#inlaysettings .check_list_box span.selected");
                if(inventorylistCb.length==1){
                    var valTechnics=inventorylistCb.attr("data-technics");
                    $("#_batchTechnics").val(valTechnics);
                }else{
                    $("#_batchTechnics").html(html_Technics);
                }
            });
            //批量修改汇率
            $("#rate_btn").on("click",function(){
                myApp.popup("#ModRate_box");
            });

            //推荐start
            $("#recommend_btn").on('click',function(){
                $("#title_tab_recommend span.active").css("background",$.cookie("ThemesColor"));
                $('#search_status_box .search_tag').html('')
                myApp.popup("#tag_box");
                getRecommend();
            });
            //切换推荐成品
            $("#title_tab_recommend").on('click','span',function(){
                $(this).addClass("active").siblings().removeClass("active");
                $(this).css("background",$.cookie("ThemesColor")).siblings("span").css("background","#ccc");
                if($("#title_tab_recommend span.active").attr("data-type")==2){
                    $("#factor_recommend").hide();
                    $("#price_recommend").show();
                }else{
                    $("#factor_recommend").show();
                    $("#price_recommend").hide();
                }
            });


            $('#recommend_table').on('click','.edit_btn_tag',function(){
                var idEdit=$(this).attr("data-id");
                var shortTag=$(this).attr("data-ShortTag")
                var recommend=$(this).attr("data-Recommend");
                var flagTag=$(this).attr("data-FlagTag");
                if(flagTag==1 || flagTag=="1"){
                    $("#_recommend input[type='checkbox']").prop("checked",true);
                }else{
                    $("#_recommend input[type='checkbox']").prop("checked",false);
                }
                $("#recommend").val(recommend);
                $("#recommend").attr('data-id',idEdit);
                $("#recommend").attr('data-ShortTag',shortTag);

                $('.addRecommend').val('编辑')
            })
            $("#recommend_inp").on('click',function(){
               self.modifyTag();
            });
            //推荐end

            var aValidate = $("#_receipt").validate({
                debug: true, //调试模式取消submit的默认提交功能
                focusInvalid: false, //当为false时，验证无效时，没有焦点响应
                onkeyup: false,
                submitHandler: function (form) {   //表单提交句柄,为一回调函数，带一个参数：form
                    self.payMethod();//付款
                },
                rules: {
                    ArrivalTime: "required",
                    BankID: "required",
                },
                messages: {
                    ArrivalTime: "",
                    BankID:"",
                }
            });

            //买价
            var validate = $("#_modPurchasePrice").validate({
                debug: true, //调试模式取消submit的默认提交功能
                focusInvalid: false, //当为false时，验证无效时，没有焦点响应
                onkeyup: false,
                submitHandler: function (form) {   //表单提交句柄,为一回调函数，带一个参数：form
                    self.ModifyPurchasePrice();//修改买价
                },
                rules: {
                    PurchaseUSD: "required",
                    PurchaseRMB: "required",
                },
                messages: {
                    PurchaseUSD: "",
                    PurchaseRMB: "",
                }
            });

            //批量修改款号
            var validate = $("#_modStyleNo").validate({
                debug: true, //调试模式取消submit的默认提交功能
                focusInvalid: false, //当为false时，验证无效时，没有焦点响应
                onkeyup: false,
                submitHandler: function (form) {   //表单提交句柄,为一回调函数，带一个参数：form
                    self.batchUpdateDia(4,"#batch_styleNo_box");//修改款号
                },
                rules: {

                    StyleNo: "required",

                },
                messages: {
                    StyleNo: "",
                }
            });

            //批量修改系列
            var validate = $("#_modSeries").validate({
                debug: true, //调试模式取消submit的默认提交功能
                focusInvalid: false, //当为false时，验证无效时，没有焦点响应
                onkeyup: false,
                submitHandler: function (form) {   //表单提交句柄,为一回调函数，带一个参数：form
                    self.batchUpdateDia(6,"#batch_series_box");
                },
                rules: {
                    Series: "required",

                },
                messages: {
                    Series: "",
                }
            });

            //批量修改成品证书
            //修改成品证书
            var validate = $("#_modcerttype").validate({
                debug: true, //调试模式取消submit的默认提交功能
                focusInvalid: false, //当为false时，验证无效时，没有焦点响应
                onkeyup: false,
                submitHandler: function (form) {   //表单提交句柄,为一回调函数，带一个参数：form
                    self.batchUpdateDia(7,"#batch_certtype_box");
                },
                rules: {
                    certtype: "required",
                },
                messages: {
                    certtype: "",
                }
            });

            //修改汇率
            var validate = $("#_modRate").validate({
                debug: true, //调试模式取消submit的默认提交功能
                focusInvalid: false, //当为false时，验证无效时，没有焦点响应
                onkeyup: false,
                submitHandler: function (form) {   //表单提交句柄,为一回调函数，带一个参数：form
                    self.batchUpdateDia(7,"#ModRate_box");//付款
                },
                rules: {
                    value: "required",
                },
                messages: {
                    value: "",
                }
            });

            //批量修改空托主石工艺
            var validate = $("#_modTechnics").validate({
                debug: true, //调试模式取消submit的默认提交功能
                focusInvalid: false, //当为false时，验证无效时，没有焦点响应
                onkeyup: false,
                submitHandler: function (form) {   //表单提交句柄,为一回调函数，带一个参数：form
                    self.ModifyTechnics();
                },
                rules: {
                    Technics: "required",

                },
                messages: {
                    Technics: "",
                }
            });



        },

        //清空按钮的状态
        clearBtn:function(){
            $(".search_btn_b").css("background-color","#a1a1a1");
            $(".search_btn_b").attr("disabled",true);
        },

        //批量修改
        batchUpdateDia:function(val,lib) {
            var self=this;
            myApp.showPreloader(_("修改中，请稍等!"));
            //组装参数start
            var request = {};
            request.filter = {};
            request.filter.ID = [];
            if(sType == 3){
                var inventorylistCb = $("#inlays .check_list_box span.selected");//checked的
            }else if(sType == 7){
                var inventorylistCb = $("#inlaysettings .check_list_box span.selected");//checked的
            }
            for (var i = 0; i < inventorylistCb.length; i++) {
                request.filter.ID[i] = inventorylistCb[i].lang;
            }
            request.GoodsType=sType;
            var submitUrl="/Team/ModifyProducts";
            if(val==1){//批量修改所在地
                request.Country = $("#place_box").val();
            }else if(val==2){ //批量修改状态
                request.Status=$("#_batchstatus").val();
                request.Remark=$("#ModStatus_Comments").val();
            }else if(val==3){ //批量修改到货时间
                request.ArrivalTime=$("#arrival_time").val();
            }else if(val==4){ //批量修改款号
                request.StyleNo=$("#_batchStyleNo").val();
            }else if(val==5){ //批量修改风格
                request.Style=$("#_batchStyle").val();
            }else if(val==6){ //批量修改系列
                request.Series=$("#_batchSeries").val();
            }else if(val==7){ //批量修改汇率
                request.PurchaseExchange=$("#mod_rate").val();
            }
            $.ajax({
                url: submitUrl,//提交地址
                type: "POST",//提交方式
                data: JSON.stringify(request),
                contentType: "application/json; charset=utf-8",
                timeout: 30000, //超时时间：30秒
                success: function (result) {
                    var data=eval('('+result+')');
                    indexCount=1;
                    myApp.hidePreloader();//隐藏加载中
                    if(data.result==true){
                        toast(_("修改成功"));
                        myApp.closeModal(lib)
                        if(sType == 3){
                            $("#inlays").html('');
                        }else if(sType ==7){
                            $("#inlaysettings").html('');
                        }
                        loadInlays();//获取库存
                    }else{
                        myApp.alert(_("修改失败"));
                    }

                },
                error: function(XMLHttpRequest, textStatus, errorThrown){
                    myApp.hidePreloader();//隐藏加载中
                    myApp.alert("网络超时，请重试");
                },
            });
        },

        //批量修改调价
        ModifyPrice:function(){
            var request = {};
            request.filter = {};
            request.filter.ID = [];
            var inventorylistCb =$("#inlays .check_list_box span.selected");//checked的
            for (var i = 0; i < inventorylistCb.length; i++) {
                request.filter.ID[i] = inventorylistCb[i].lang;
            }
            request.GoodsType=sType;

            var URL;
            if($("#title_tab span.active").attr("data-type")==2){
                request.Price=$("#_Price").val();
                URL="/team/ModifyProducts";
            }else{
                request.factor = $("#_factor").val();
                request.field="Price";
                URL="/team/UpdateProductPrice";
            }
            $.ajax({
                type:"post",
                url:URL,
                data:JSON.stringify(request),
                contentType:"application/json; charset=utf-8",
                timeout: 30000, //超时时间：30秒
                success: function (result) {
                    var data=JSON.parse(result);
                    indexCount=1;
                    myApp.hidePreloader();//隐藏加载中
                    if(data.result==true){
                        toast(_("修改成功"));
                        $("#batchDia_box").hide();
                        $("#inlays").html('');
                            loadInlays();//获取库存
                    }else{
                        myApp.alert(_("修改失败"));
                    }
                },
                error: function(XMLHttpRequest, textStatus, errorThrown){
                    myApp.hidePreloader();//隐藏加载中
                    myApp.alert("网络超时，请重试");
                }
            });
        },
        //付款账户
        ReceiptOrders_Js:function(){
            //仅管理员1 和 财务2
            if (RoleID == 1 || RoleID == 2 || RoleID == 6) {
                myApp.popup("#pay_box");
                var requestJson={};
                requestJson.Status=1;
                requestJson.CheckResult=1;
                if($.cookie("CurrentSet") == 2){
                    requestJson.Currency=2;
                }
                if($.cookie("CurrentSet") == 1){
                    requestJson.Currency=1;
                }
                //付款账户
                $.ajax({
                    url: "/Team/GetBankList",//提交地址
                    type: "POST",//提交方式
                    data: JSON.stringify(requestJson),
                    contentType: "application/json; charset=utf-8",
                    success: function (result) {
                        var _result = JSON.parse(result);//eval()解析单个json对象

                        var options = "";
                        options += '<option value="">'+_("选择账户")+'</option>';
                        for (var i = 0; i < _result.length; i++) {
                            options += '<option value="' + _result[i].BankID + '" data-type="'+_result[i].Currency+'">【' + _result[i].BankName + '】' + _result[i].BankBalance + '' + CurrencyFormat(_result[i].Currency) + '</option>';
                        }
                        $("#_receiptBankID").html("");
                        $("#_receiptBankID").html(options);
                    }
                });
            } else {
                myApp.alert(_("【付款】禁用"));
            }
        },
        //批量修改付款
        payMethod:function(){
            var request = {};
            request.filter = {};
            request.filter.ID = [];
            if(sType==3){
                var inventorylistCb = $("#inlays .check_list_box span.selected");//checked的
            }else if(sType == 7){
                var inventorylistCb = $("#inlaysettings .check_list_box span.selected");//checked的
            }
            for (var i = 0; i < inventorylistCb.length; i++) {
                request.filter.ID[i] = inventorylistCb[i].lang;
            }
            request.GoodsType=sType;
            request.ReceiptStatus=1;//已付状态
            request.UserID=UserID;//操作人
            var currency=$("#_receiptBankID option:checked").attr("data-type");//1人民币 2美金
            request.Currency=currency;
            if(currency==1){//人民币
                request.TotalMoney=Number($("#_receipt_rmb").text());//人民币价格
            }else {
                request.TotalMoney=$("#_receipt_usd").text();//美金价格
            }
            request.ArrivalTime=$("#receiptarrivalTime").val();
            request.BankID=$("#_receiptBankID").val();
            $.ajax({
                type:"post",
                url:"/Team/UpdateProductPayStatus",
                data:JSON.stringify(request),
                contentType:"application/json; charset=utf-8",
                timeout: 30000, //超时时间：30秒
                success: function (result) {
                    var data=JSON.parse(result);
                    indexCount=1;
                    myApp.hidePreloader();//隐藏加载中
                    if(data.msgcode==true){
                        toast(_("修改成功"));
                        // $("#pay_box").hide();
                        myApp.closeModal("#pay_box")
                        if(sType == 3){
                            $("#inlays").html('');
                        }else if(sType == 7){
                            $("#inlaysettings").html('');
                        }
                        loadInlays();//获取库存
                    }else{
                        myApp.alert(_(data.msginfo));
                    }
                },
                error: function(XMLHttpRequest, textStatus, errorThrown){
                    myApp.hidePreloader();//隐藏加载中
                    myApp.alert("网络超时，请重试");
                }
            });
        },
        //批量删除
        delDia:function(){
            myApp.showPreloader(_("修改中，请稍等!"));
            var self=this;
            var submitJson={};
            submitJson.filter={};
            submitJson.filter.ID=[]
            var inventorylistCb = $("#inlays .check_list_box span.selected");//checked的
            for (var i = 0; i < inventorylistCb.length; i++) {
                submitJson.filter.ID[i] = inventorylistCb[i].lang;
                submitJson.filter.limit=1000;
            }
            submitJson.GoodsType=sType;

            $.ajax({
                url: "/Team/DelteProducts",//提交地址
                type: "POST",//提交方式
                data: JSON.stringify(submitJson),
                contentType: "application/json; charset=utf-8",
                timeout: 30000, //超时时间：30秒
                success: function (result) {
                    var _result = eval('(' + result + ')');//eval()解析单个json对象
                    indexCount=1;
                    myApp.hidePreloader();//隐藏加载中
                    if (_result.result == true) {
                        myApp.alert("删除成功")
                        $("#inlays").html('');
                        loadInlays();//获取库存
                    } else {
                        myApp.alert(_(_result.msginfo));//删除失败
                    }
                },
                error: function(XMLHttpRequest, textStatus, errorThrown){
                    myApp.hidePreloader();//隐藏加载中
                    myApp.alert("网络超时，请重试");
                }
            });
        },

        //上下架
        productOnShelves:function(){
            var submitJson={};
            var _type=$("#form_shelves_choose span.active").attr("data-type");//1为上架，0为下架
            if(_type == 1){
                var valText=_("确定上架选中的产品？");
            }else{
                var valText=_("确定下架选中的产品？");
            }
            submitJson.filter={};
            submitJson.filter.ID=[];
            if(sType == 3){
                var inventorylistCb = $("#inlays .check_list_box span.selected");//checked的
            }else if(sType == 7){
                var inventorylistCb = $("#inlaysettings .check_list_box span.selected");//checked的
            }
            for (var i = 0; i < inventorylistCb.length; i++) {
                submitJson.filter.ID[i] = inventorylistCb[i].lang;
            }
            submitJson.filter.limit=1000;
            submitJson.OnShelves=_type;
            submitJson.GoodsType=sType;
            submitJson=JSON.stringify(submitJson);
            myApp.confirm(valText,function() {
                myApp.showPreloader(_("修改中，请稍等!"));
                $.ajax({
                    url: '/team/ModifyProducts',//提交地址
                    type: "POST",//提交方式
                    data: submitJson,
                    contentType: "application/json; charset=utf-8",
                    timeout: 30000, //超时时间：30秒
                    success: function (result) {
                        var data=JSON.parse(result);
                        indexCount=1;
                        myApp.hidePreloader();//隐藏加载中
                        if(data.result==true){
                            toast(_("修改成功"));
                            $("#shelves_box").hide();
                            if(sType == 3){
                                $("#inlays").html('');
                            }else if(sType == 7){
                                $("#inlaysettings").html('');
                            }
                            loadInlays();//获取库存
                        }else{
                            myApp.alert(_("修改失败"));
                        }
                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown){
                        myApp.hidePreloader();//隐藏加载中
                        myApp.alert("网络超时，请重试");
                    }
                });
            });
        },

        //批量修改买价
        ModifyPurchasePrice:function(){
            //组装参数start
            var request = {};
            request.filter = {};
            request.filter.ID = [];
            var inventorylistCb =$("#inlays .check_list_box span.selected");//checked的
            for (var i = 0; i < inventorylistCb.length; i++) {
                request.filter.ID[i] = inventorylistCb[i].lang;
            }
            if($('#origin_radio_purchaseUSD:checked').length!=0){
                request.PurchaseUSD = $("#purchaseUSD_inp").val();
            }
            if($('#origin_radio_purchaseRMB:checked').length!=0){
                request.PurchaseRMB = $("#purchaseRMB_inp").val();
            }
            request.GoodsType=sType;
            $.ajax({
                url: "/team/ModifyProducts",//提交地址
                type: "POST",//提交方式
                data: JSON.stringify(request),
                contentType: "application/json; charset=utf-8",
                timeout: 30000, //超时时间：30秒
                success: function (result) {
                    var data=JSON.parse(result);
                    indexCount=1;
                    myApp.hidePreloader();//隐藏加载中
                    if(data.result==true){
                        toast(_("修改成功"));
                        $("#ModPurchasePrice_box").hide();
                        $("#inlays").html('');
                        loadInlays();//获取库存
                    }else{
                        myApp.alert(_("修改失败"));
                    }
                },
                error: function(XMLHttpRequest, textStatus, errorThrown){
                    myApp.hidePreloader();//隐藏加载中
                    myApp.alert("网络超时，请重试");
                }
            });
        },

        //批量修改推荐
        modifyTag:function(){
            var request = {};
            request.filter = {};
            request.filter.ID = [];
            if(sType == 3){
                var inventorylistCb = $("#inlays .check_list_box span.selected");
            }else if(sType == 7){
                var inventorylistCb = $("#inlaysettings .check_list_box span.selected");
            }
            for (var i = 0; i < inventorylistCb.length; i++) {
                request.filter.ID[i] = inventorylistCb[i].lang;
            }
            if($('#recommend_form input[name="Recommend"]:checked').val()>0){
                request.Tag = $('#recommend_form input[name="Recommend"]:checked').val();
            }else{
                request.Tag=0;
            }
            request.GoodsType=sType;
            $.ajax({
                url: "/Team/ModifyProducts",//提交地址
                type: "POST",//提交方式
                data: JSON.stringify(request),
                contentType: "application/json; charset=utf-8",
                timeout: 30000, //超时时间：30秒
                success: function (result) {
                    var data=JSON.parse(result);
                    indexCount=1;
                    myApp.hidePreloader();//隐藏加载中
                    if(data.result==true){
                        toast(_("修改成功"));
                        $("#tag_box").hide();
                        if(sType == 3){
                            $("#inlays").html('');
                        }else if(sType == 7){
                            $("#inlaysettings").html('');
                        }
                        loadInlays();//获取库存
                    }else{
                        myApp.alert(_("修改失败"));
                    }
                },
                error: function(XMLHttpRequest, textStatus, errorThrown){
                    myApp.hidePreloader();//隐藏加载中
                    myApp.alert("网络超时，请重试");
                }
            });
        },

        //空托批量调价
        ModifyPriceInlays:function(){
            btnDisable("#ModPrice_btn");
            var request = {};
            request.filter = {};
            request.filter.ID = [];
            var inventorylistCb = $("#inlaysettings .check_list_box span.selected");//checked的
            for (var i = 0; i < inventorylistCb.length; i++) {
                request.filter.ID[i] = inventorylistCb[i].lang;
            }
            if($("#mod_Wastage").val()!=""){
                request.Wastage=$("#mod_Wastage").val()
            }
            if($("#mod_LaborFee").val()!=""){
                request.LaborFee=$("#mod_LaborFee").val()
            }
            if($("#mod_SideLaborFee").val()!=""){
                request.SideLaborFee=$("#mod_SideLaborFee").val()
            }
            if($("#mod_SidePrice").val()!=""){
                request.SidePrice=$("#mod_SidePrice").val()
            }
            if($("#mod_Insurance").val()!=""){
                request.Insurance=$("#mod_Insurance").val()
            }
            request.GoodsType=7;
            $.ajax({
                type:"post",
                url:"/team/ModifyProducts",
                data:JSON.stringify(request),
                contentType:"application/json; charset=utf-8",
                timeout: 30000, //超时时间：30秒
                success: function (result) {
                    var data=eval('('+result+')');
                    indexCount=1;
                    if(data.result==true){
                        $("#batch_price_box").hide();
                        toast(_("修改成功"));
                        $("#inlaysettings").html('');
                        loadInlays();
                    }else{
                        myApp.alert(_("修改失败"));
                    }
                },
                error: function(XMLHttpRequest, textStatus, errorThrown){
                    myApp.hidePreloader();//隐藏加载中
                    myApp.alert("网络超时，请重试");
                }
            });

        },
        //批量修改主石工艺空托
        ModifyTechnics:function(){
            var request = {};
            request.filter = {};
            request.filter.ID = [];
            var inventorylistCb = $("#inlaysettings .check_list_box span.selected");//checked的
            for (var i = 0; i < inventorylistCb.length; i++) {
                request.filter.ID[i] = inventorylistCb[i].lang;
            }

            request.Technics=$("#_batchTechnics").val();
            request.GoodsType=7;

            $.ajax({
                url: "/Team/ModifyProducts",//提交地址
                type: "POST",//提交方式
                data: JSON.stringify(request),
                contentType: "application/json; charset=utf-8",
                timeout: 30000, //超时时间：30秒
                success: function (result) {
                    var data=eval('('+result+')');
                    indexCount=1;
                    if(data.result==true){
                        $("#batch_technics_box").hide();
                        toast(_("修改成功"));
                        $("#inlaysettings").html('');
                        loadInlays();
                    }else{
                        myApp.alert(_("修改失败"));
                    }
                },
                error: function(XMLHttpRequest, textStatus, errorThrown){
                    myApp.hidePreloader();//隐藏加载中
                    myApp.alert("网络超时，请重试");
                }
            });
        },

    }

    product.init();
}());

//获取推荐名称
function getRecommend(){
    $.ajax({
        url: "/Team/GetRecommend",//提交地址
        type: "POST",//提交方式
        contentType: "application/json; charset=utf-8",
        success: function (result) {
            var result = eval('(' + result + ')');//eval()解析单个json对象
            var html = [];
            var htmlList=[];
            $('#recommend_body').html('');
            $('#recommend_form').html('');
            if (result.msgcode == true) {

                recommendNum = result.msginfo.length + 1;

                var $remommend; //单个修改推荐显示下拉框
                var $searchTag=[]; //筛选
                $remommend = '<option value="0"></option>'
                for (var i = 0; i < result.msginfo.length; i++) {
                    $remommend += '<option value="' + result.msginfo[i].ShortTag + '">' + _(result.msginfo[i].RecommendName) + '</option>';
                    if(result.msginfo[i].FlagTag == 1 || result.msginfo[i].FlagTag == "1") {
                        $searchTag.push([
                            '<a href="#" data-value_tag="' + result.msginfo[i].ShortTag + '"> ' + _(result.msginfo[i].RecommendName) + ' </a>'
                        ].join(''))
                    }
                }

                $("#form_Tag").html($remommend);
                $('#search_status_box .search_tag').append($searchTag.join(''));
                //单个修改推荐显示下拉框end 筛选end
                htmlList.push([
                    '<div class="form-group" style="height:15px;margin-left:72px">',
                    '<label for="rmb" class="form_i_qq">取消推荐<input type="radio" name="Recommend" style="margin-left:17px"  value="0"  /></label>',
                    '</div>'
                ].join(''));
                if (result.msginfo.length > 0) {
                    for (var i = 0; i < result.msginfo.length; i++) {
                        var row = result.msginfo[i];
                        //修改 推荐 start
                        html.push([
                            '<tr style="color:#555">',
                            '<td>'+row.RecommendName+'</td>',  //推荐
                            '<td>'+row.ShortTag+'</td>',  //排序
                            '<td>'+formatTag(row.FlagTag)+'</td>',  //启用
                            '<td><span class="modify edit_btn_tag" data-id="'+row.ID+'" data-Recommend="'+row.RecommendName+'" data-ShortTag="'+row.ShortTag+'" data-FlagTag="'+row.FlagTag+'">编辑</span></td>',
                            '</tr>'
                        ].join(''));
                        //修改 推荐 end

                        //确定推荐 设置 start
                        if(row.FlagTag == 1 || row.FlagTag == "1"){
                            htmlList.push([
                                '<div class="form-group" style="height:15px;margin-left:100px">',
                                '<label for="rmb" class="form_i_qq">' + row.RecommendName + '<input type="radio" name="Recommend" style="margin-left:15px" data-id="' + row.ID + '" data-Recommend="' + row.RecommendName + '" value="' + row.ShortTag + '"  /></label>',
                                '</div>'
                            ].join(''));
                        }
                        //确定推荐 设置 end

                    }
                }


            }else {
                recommendNum=1;
                html.push([
                    '<tr>',
                    '<td style="color:red" colspan="13">请先设置推荐名称</tds>',
                    '</tr>'
                ].join(''));

                htmlList.push([
                    '<div class="form-group" style="height:28px;margin-left:15%">',
                    '<label for="rmb" class="form_i_qq" style="color:red">请先设置推荐名称</label>',
                    '</div>'
                ].join(''));
            }
            $("#recommend_body").append(html.join('')); //推荐
            $("#recommend_form").append(htmlList.join('')); //设置
            inputChecked();
        }
    });
}

//推荐选中
function inputChecked() {
    if(sType == 3){
        var inventorylistCb = $("#inlays .check_list_box span.selected");
    }else if(sType == 7){
        var inventorylistCb = $("#inlaysettings .check_list_box span.selected");
    }
    if(inventorylistCb.length==1){
        var valTag=inventorylistCb.attr("data-Tag");
        $("#recommend_form input[value="+valTag+"]").attr("checked",true);
    }else{
        $("input[name='Recommend']").prop("checked",false);
        $("#recommend").val('');
    }
}
//修改推荐
function mobileDia(){
    var Url=''
    var param={};
    param.UserID=UserID;
    if($("#remember_recommend").prop("checked")){
        param.FlagTag =1
    }else{
        param.FlagTag =0
    }
    if($('#recommend').val()!=''){
        param.RecommendName=$('#recommend').val();
    }else{
        alertMsgBox('推荐内容不能为空');
        return false;
    }
    if($('#recommend').attr('data-id')!=''){
        param.ShortTag=Number($("#recommend").attr('data-shorttag'));
        Url="/Team/ModifyRecommend";
        param.ID=$('#recommend').attr('data-id');
    }else {
        param.ShortTag=recommendNum;
        Url="/Team/AddRecommend";
    }

    $.ajax({
        url: Url,//提交地址
        type: "POST",//提交方式
        data: JSON.stringify(param),
        contentType: "application/json; charset=utf-8",
        success: function (result) {
            var _result = eval('(' + result + ')');//eval()解析单个json对象
            $("#search_status_box .search_tag").html('');
            if (_result.msgcode==true) {
                myApp.alert(_(_result["msginfo"]));
                $('#recommend').attr('data-id','');
                $('#recommend').val('');
                $('.addRecommend').val('添加');
                getRecommend();
            } else {
                myApp.alert(_(_result["msginfo"]));
            }
        }
    });

}

//是否格式化
function formatTag(tagVal){
    if(tagVal == 1 || tagVal == "1"){
        return '是';
    }else if(tagVal == 0 || tagVal == "0"){
        return '否';
    }else{
        return tagVal;
    }
}

//买价切换
function PurceaseUSDChange(){  //采$
    $("#Discount_box").hide();
    $("#DiscountReturn_box").show();
}

function PurchaseRMBChange(){
    $("#DiscountReturn_box").hide();
    $("#Discount_box").show();
}




